package com.web44.ssm.web;

import com.web44.ssm.bean.Adminuser;
import com.web44.ssm.service.impl.AdminuserService;
import com.web44.ssm.utils.ResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Title: AdminuserController
 * @Description:
 * @Auther: py
 * @Version: 1.0
 * @create 2024/2/18 11:06
 */
@RestController
@RequestMapping("adminuser")
public class AdminuserController {

    @Autowired
    private AdminuserService adminuserService;

    @GetMapping("test")
    @ResponseBody
    public ResponseVo testWeb() {
        System.out.println(1/0);
        return ResponseVo.ok("登录成功！");

    }

    @PostMapping("login")
    public ResponseVo adminLoginWeb(@RequestBody Adminuser adminuser) {
        String username = adminuser.getUsername();
        String password = adminuser.getPassword();
        Adminuser adminuser1 = adminuserService.queryAdminuserByUsername(username);
        if(adminuser1 == null) {
            throw  new RuntimeException("用户不存在！");
        }
        if(!adminuser1.getPassword().equals(password)) {
            throw  new RuntimeException("密码错误！");
        }

        return ResponseVo.ok("登录成功！",adminuser1);



    }
}
